package com.shujia.mllib

import org.wltea.analyzer.core.{IKSegmenter, Lexeme}

import java.io.StringReader
import scala.collection.mutable.ListBuffer

object Demo08IK {
  def main(args: Array[String]): Unit = {
    val str: String = "房价是涨是跌看神马报道都不管用重点看卖地的价格是涨是跌这个才是风向标"

    val words: List[String] = Demo08IK.fit(str)

    println(words)

    println(Demo08IK.fit("武汉市长江大桥"))
    println(Demo08IK.fit("艾伦麦席森图灵"))

  }

  def fit(str: String): List[String] = {
    val reader = new StringReader(str)
    val listBuffer: ListBuffer[String] = ListBuffer[String]()
    // 使用分词器对词语进行分词
    val ik = new IKSegmenter(reader, true)
    var lexeme: Lexeme = ik.next()
    while (lexeme != null) {
      listBuffer.append(lexeme.getLexemeText)
      lexeme = ik.next()
    }
    listBuffer.toList
  }

}
